
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/addNewRegion.do"/>

<html:html locale="true">

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>


<script language='javascript'>
function save()
{
    var errors = '';
    var region = document.addNewRegionForm.newRegion.value;
    if( region.value != '')
    {
            if( region.trim().length == 0)
            {
                errors = errors + "<li> Please enter Region Name";
            }

    }

    if(errors != '')
    {
        var inf = document.getElementById("infoMessagesId");
        inf.innerHTML = '';
        var err = document.getElementById("errorMessagesId");
        err.innerHTML = '';

        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return false;
    }

   //var customerId = window.opener.document.customerForm['customer.customerId'].value;
  // alert(customerId);
   //document.addNewRegionForm.action = '<%=chipTracContext%>/addNewRegion.do?action=insertRegion';
   var oldRegion = document.addNewRegionForm.oldRegion.value;
   if ( oldRegion == '' )
   {
        document.addNewRegionForm.action = '<%=chipTracContext%>/addNewRegion.do?action=insertRegion';
   }
   else
   {
        document.addNewRegionForm.action = '<%=chipTracContext%>/addNewRegion.do?action=editRegion';
   }
   return true;

    //document.addNewRegionForm.submit();
}
function reset(){
    document.addNewRegionForm.reset();
}
function closeWindow(form) {
    window.opener.document.customerForm['customer.customerNumber'].disabled=false;
    window.opener.document.customerForm.submit();
 	window.close();
}
//Added by varma 7 Jan 2005 to loadthe selected region to edit
function loadRegion( regionName )
{
    document.addNewRegionForm.newRegion.value = regionName;
    document.addNewRegionForm.oldRegion.value = regionName;
    //Added to reset the Info and Error Messages
    var inf = document.getElementById("infoMessagesId");
    inf.innerHTML = '';
    var err = document.getElementById("errorMessagesId");
    err.innerHTML = '';
}

function showErrorReportPage()
{
    newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
    newWindow.focus();
}

</script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- from here your body starts -->

<!-- html:form name="addNewRegionForm" type="com.scalar.chiptrack.sales.forms.AddNewRegionForm" action='/addNewRegion.do?action=insertRegion&customerId=<%=request.getParameter("customerId")%>' -->
<!-- Modified by veeru on 12th May 2004 to submit the form even when we press enter in the new region field -->
<%-- <html:form name="addNewRegionForm" type="com.scalar.chiptrack.sales.forms.AddNewRegionForm" action='/addNewRegion.do' > --%>
<html:form name="addNewRegionForm" type="com.scalar.chiptrack.sales.forms.AddNewRegionForm" action='/addNewRegion.do?action=insertRegion' onsubmit="javascript:return save();" scope="request">

<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>
<center><span class="NArialW">Region</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<table border="0" width="90%" align=center>
 <tr><td>
 <table border="0" width="100%" cellspacing='10' cellpadding='2' align='center'>
 <tr><td colspan=2 align=right><a href="javascript:closeWindow(document.addNewRegionForm);" onMouseOver="window.status='Click here to close this window';return true" onmouseout="window.status='';return true" ><font class='NArialL'>Close this window</font></a></td></tr>
 <tr><td colspan='2' id='errorMessagesId'><chiptrack:errors styleClass='NArialL' /></td></tr>
 <tr><td colspan='2' id='infoMessagesId'><chiptrack:info styleClass='NArialL' /> </td></tr>


    <!--tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer/gif" height=10></td></tr-->
    <tr><td colspan='2' align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></TD></TR>

	<tr>
        <td colspan='2' nowrap><font class="NArialL">Region Name:<font color=red>*</font>&nbsp;&nbsp;</font>
			<html:text property="newRegion" size="25" maxlength="<%=ConfigManager.getProperty(ConfigManager.REGION_NAME_MAX_LENGTH)%>" styleClass="txfield"/>
            <input type="hidden" name="oldRegion" value="">
		</td>

    </tr>

	<tr>
        <td colspan='1' nowrap align='center'>
		     <%--<a href="javascript:save()" onmouseover="window.status='Click to Add Region';return true" onmouseout="window.status='';return true" title="Click here to Add Region"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>--%>
             <input type=image border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17" onmouseover="window.status='Click to Save Region';return true" onmouseout="window.status='';return true" title="Click here to Save Region">
	    </td>
		<td colspan='1' nowrap align='left'>
		     <a href="javascript:reset()" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
	    </td>
    </tr>

  </table>

  </td></tr>
  <!--tr><td><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr-->
  <tr><td>

<!-- DISPLAY ALL USERS STARTS HERE -->

<% ArrayList regions = (ArrayList) request.getAttribute("regions");
	if( regions != null && regions.size() != 0 ) { %>

   <table border="0" width="100%" bordercolor="#FFFFFF" align='center'>
    <tr>
        <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Region </font></font></td>
        <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Action</font></font></td>
       <%-- <td width="15%">&nbsp;</td>--%>
    </tr>

    <% int bgcount = 0;%>
    <logic:iterate id="Region" name="regions" type="com.scalar.chiptrack.sales.Region">
    <% bgcount = bgcount + 1; %>
    <tr>
    <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
    <bean:write name="Region" property="region" /></font></td>
    <td nowrap width="15%" align="center" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
     <logic:equal name="Region" property="disabled" value="true">
     <a href='<%=chipTracContext%>/addNewRegion.do?regionstatus=disable&region=<bean:write name="Region" property="encodeRegion" />&regionId=<bean:write name="Region" property="regionId" />'>Disable</a>&nbsp;&nbsp;
     </logic:equal>
     <logic:equal name="Region" property="disabled" value="false">
     <a href='<%=chipTracContext%>/addNewRegion.do?regionstatus=activate&region=<bean:write name="Region" property="encodeRegion" />&regionId=<bean:write name="Region" property="regionId" />' ><font color='red'> Activate</font></a>&nbsp;
     </logic:equal>
     <a href="javascript:loadRegion('<bean:write name="Region" property="region" />');" onMouseOver="window.status='Click to Edit Region';return true" onmouseout="window.status='';return true">Edit</a>
     </font></td>

    </tr>
    </logic:iterate>

    <tr><td class="NArialL" colspan=5><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=50></td></tr>
    <tr><td colspan=3 align=center><a href="javascript:closeWindow(document.addNewRepOfficeForm);" onMouseOver="window.status='Click here to close this window';return true"><font class='NArialL'>Close this window</font></a></td></tr>

    </table>
	<% } %>

<!-- DISPLAY ALL USERS ENDS HERE -->

</td></tr>
</table>
<input type="hidden" name="customerId" value ='<%=request.getParameter("customerId")%>' >

</html:form>


</body>

</html:html>